import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const requireComponent = require.context('./modules', false, /\.js$/)
let main = [
  {
    path: '/index',
    name: 'index',
    component: () => import('../pages/index/index'),
    meta: {
      title: '数据总览',
      showTitle: true
    }
  }
]

requireComponent.keys().forEach(fileName => {
  const componentConfig = requireComponent(fileName)
  main.push(...componentConfig.default)
})
const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('../pages/main/login')
  },
  {
    path: '/',
    name: 'main',
    component: () => import('@/pages/main/main'),
    redirect: 'index',
    meta: {
      title: '首页'
    },
    children: [...main]
  }
]
export default new Router({
  routes
})
